package edu.uestc.canary.commons.files.config;

import edu.uestc.canary.commons.files.service.FileService;
import io.minio.MinioClient;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(MinioConfigProperties.class)
//当引入FileService接口时,自动装配bean
@ConditionalOnClass(FileService.class)
public class MinioConfig {
    @Resource private MinioConfigProperties properties;
    @Bean
    public MinioClient minioClient(){
        return MinioClient.builder()
                .credentials(properties.getAccessKey(), properties.getSecretKey())
                .endpoint(properties.getEndpoint())
                .build();
    }
}
